
import { PluginOption } from "vite";
import { templateList } from "./fun/templateList";
import { list } from "./fun/list";
import { add } from "./fun/add";
import { buildStartDictionary, createDictionary } from "./fun/createDictionary";
import { see } from "./fun/see";

/**
 * 能力管理插件
 */
export default function (): PluginOption[] {
    return [{
        name: 'vite-capability-manage',
        apply: 'serve',
        configureServer(server) {

            server.watcher.on('change', createDictionary);
            server.watcher.on('add', createDictionary);
            server.watcher.on('unlink', createDictionary);

            // 模块模版列表
            server.middlewares.use('/dev/capability/templateList', templateList);

            // 获取制定模块的能力列表
            server.middlewares.use('/dev/capability/list', list);

            // 获取制定模块的能力列表
            server.middlewares.use('/dev/capability/add', add);

            // 获取制定模块的能力列表
            server.middlewares.use('/dev/capability/see', see);
        },

        buildStart() {
            buildStartDictionary();
        },
    }]
}